#include "Sprite.h"

Sprite::Sprite( )
{
	srand( unsigned int( time(NULL) ) ) ;
	position = D3DXVECTOR3( 0, 0, 0 ) ;
	tag = NORMAL ;
	justInfected = false ;

	sprAdj = new Adj ;

	sprAdj->bottom = sprAdj->left = sprAdj->top = sprAdj->right = NULL ;
}

Sprite::~Sprite( )
{
}

void Sprite::CureCheck( int rate )
{
	if( ( rand( ) % 100 + 1 ) <= rate )
		tag = NORMAL ;
}

void Sprite::InfectionCheck( Sprite* target, int rate )
{
	if( target != NULL )
		if( target->checkTag( ) == NORMAL )
			if( ( rand( ) % 100 + 1 ) <= rate || tag == CARRIER )
			{
				target->tag = INFECTED ;
				target->justInfected = true ;
			}
}

void Sprite::ResetSprite( )
{
	tag = NORMAL ;
	justInfected = false ;
}

void Sprite::TurnSprite( )
{
	if( tag != CARRIER )
		tag = CARRIER ;
	else
		tag = NORMAL ;
}

void Sprite::FindAdjacent( Sprite& other )
{
	if( position.x - 20.0f == other.position.x && position.y == other.position.y )
		sprAdj->left = &other ;
	else if( position.x + 20.0f == other.position.x && position.y == other.position.y )
		sprAdj->right = &other ;
	else if( position.x == other.position.x && position.y - 20.0f == other.position.y )
		sprAdj->top = &other ;
	else if( position.x == other.position.x && position.y + 20.0f == other.position.y )
		sprAdj->bottom = &other ;
}